package com.hu.zhcc.shiro.controller.Appointment;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.Appointment.Entry;
import com.hu.zhcc.shiro.entity.Appointment.Entryteam;
import com.hu.zhcc.shiro.service.Appointment.EntryService;
import com.hu.zhcc.shiro.service.Appointment.EntryteamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/****
 * 检查项管理Controller
 */
@RestController
public class EntryController {

    @Autowired
    private EntryService entryService;

    @Autowired
    private EntryteamService entryteamService;

    /****
     * 分页及条件查询
     * @param offset
     * @param limit
     * @param value
     * @return
     */
    @GetMapping("selectEntryAll")
    private Page<Entry> selectEntryAll(String offset, String limit, String value) {
        Map map = new HashMap();
        map.put("offset", offset);
        map.put("limit", limit);
        return entryService.selectEntryAll(map, value);
    }

    /****
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteEntryById{id}")
    private int deleteEntryById(@PathVariable("id") int id) {
        return entryService.deleteByPrimaryKey(id);
    }

    /****
     * 添加
     * @param entry
     * @return
     */
    @PostMapping("addentry")
    private int addentry(@RequestBody Entry entry) {
        entry.settId(1);
        return entryService.insertSelective(entry);
    }

    /****
     * 修改前查询
     * @param id
     * @return
     */
    @PostMapping("beforeEditById{id}")
    private Entry beforeEditById(@PathVariable("id") int id) {
        return entryService.updateBeforeById(id);
    }

    /****
     * 修改
     * @param entry
     * @return
     */
    @PutMapping("updateEntry")
    private int updateEntry(@RequestBody Entry entry) {
        return entryService.updateByPrimaryKeySelective(entry);
    }

    /****
     * 查询项目组
     * @return
     */
    @PostMapping("allteams")
    private List<Entryteam> allteams() {
        return entryteamService.selectEntryTeamsAll();
    }
}
